package com.info.zhiduoduo.repository.mapper.marketingcooperative;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.dto.marketingcooperative.GeneratePartnerPosterDto;
import com.info.zhiduoduo.repository.dto.marketingcooperative.MarketingCooperativePartnerPosterDto;
import com.info.zhiduoduo.repository.entity.marketingcooperative.MarketingCooperativePartnerPoster;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface MarketingCooperativePartnerPosterMapper extends BaseMapper<MarketingCooperativePartnerPoster> {

	@Select(" select mcpp.*,mcpc.name posterConfigName,pa.realname partnerName,c.compname " +
			" from zdd_marketing_cooperative_partner_poster mcpp " +
			" join zdd_marketing_cooperative_poster_config mcpc on mcpc.id = mcpp.poster_config_id " +
			" join zdd_partner_account pa on pa.partnerid = mcpp.partnerid " +
			" join zdd_company c on c.compid = mcpp.compid " +
			" where mcpp.partnerid = #{partnerid} " +
			" order by mcpp.id desc")
	List<MarketingCooperativePartnerPosterDto> listByPartnerid(int partnerid);

	@Select(" select mcpp.*,mcpc.name posterConfigName,pa.realname partnerName,c.compname " +
			" from zdd_marketing_cooperative_partner_poster mcpp " +
			" join zdd_marketing_cooperative_poster_config mcpc on mcpc.id = mcpp.poster_config_id " +
			" join zdd_partner_account pa on pa.partnerid = mcpp.partnerid " +
			" join zdd_company c on c.compid = mcpp.compid " +
			" where mcpp.compid = #{compid} " +
			" order by mcpp.id desc")
	List<MarketingCooperativePartnerPosterDto> listByCompid(int compid);

	@Select("SELECT mcpp.*, mcpc.share_title,mcpc.share_description,mcpc.share_icon " +
			"FROM zdd_marketing_cooperative_partner_poster mcpp " +
			"LEFT JOIN zdd_marketing_cooperative_poster_config mcpc ON mcpc.id = mcpp.poster_config_id " +
			"WHERE mcpp.id = #{id}")
	GeneratePartnerPosterDto generatePartnerPoster(@Param("id") int id);

	@Delete("delete from zdd_marketing_cooperative_partner_poster where partnerid = #{partnerid} AND compid = #{compid} AND poster_config_id = #{posterConfigId}")
	int deleteByFormId(@Param("partnerid") int partnerid,
					   @Param("compid") int compid,
					   @Param("posterConfigId") int posterConfigId);
}
